//
//  MyViewController.m
//  SugarPile
//
//  Created by LC on 16/2/27.
//  Copyright © 2016年 www.lanou39.蓝鸥科技. All rights reserved.
//

#import "MyViewController.h"
#import "SelfViewController.h"
#import "CollectViewController.h"
#import "RecordViewController.h"
@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *mytableView; /**< 主要页面 */
@property (nonatomic, retain) NSArray *lableArr; /**< 数据 */
@property (nonatomic, retain) NSArray *imageArr;
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.lableArr = @[@"喜欢的文章", @"收藏的专辑", @"历史记录"];
    self.imageArr = @[@"xihuan", @"shoucang-1", @"lishi"];
    [_mytableView reloadData];
    // table
    [self createCollection];
    
}
- (void)createCollection
{
    self.mytableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _mytableView.delegate = self;
    _mytableView.dataSource = self;
    [self.view addSubview:_mytableView];
    [self.mytableView release];
    [_mytableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return _lableArr.count;
    }else if (section == 1){
        return 1;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.section == 0) {
        
        cell.textLabel.text = _lableArr[indexPath.row];
        cell.imageView.image = [UIImage imageNamed:_imageArr[indexPath.row]];
        // 辅助视图
    }
    if (indexPath.section == 1) {
        cell.textLabel.text = @"设置";
        cell.imageView.image = [UIImage imageNamed:@"shezhi"];
    }
    
    return cell;
}
// 点击跳转
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        if (indexPath.row == 0) {
            // 收藏
            CollectViewController *collVC = [[CollectViewController alloc] init];
            collVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:collVC animated:YES];
        }else if (indexPath.row == 2){
            // 历史记录
            RecordViewController *recordVC = [[RecordViewController alloc] init];
            recordVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:recordVC animated:YES];
        }
    }
    if (indexPath.section == 1) {
        // 设置
        SelfViewController *selfVC = [[SelfViewController alloc] init];
        [self.navigationController pushViewController:selfVC animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
